package com.itstudio.portal.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itstudio.portal.entity.RestResponse;
import com.itstudio.portal.entity.vo.RoleVo;
import com.itstudio.portal.mapper.RoleMapper;
import com.itstudio.portal.entity.Role;
import com.itstudio.portal.service.RoleService;
import com.itstudio.portal.utils.BeanCopyUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Role)表服务实现类
 *
 * @author feng
 * @since 2024-11-12 10:16:13
 */
@Service("roleService")
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public RestResponse<List<RoleVo>> getRoleListByType(Integer type){
        LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(type!=null,Role::getType, type);
        List<Role> roles = roleMapper.selectList(queryWrapper);
        List<RoleVo> roleVos = BeanCopyUtil.classListVo(roles, RoleVo.class);
        return RestResponse.success(roleVos);
    }

    @Override
    public RestResponse<List<RoleVo>> getRoleList() {
        List<Role> roles = roleMapper.selectList(null);
        List<RoleVo> roleVos = BeanCopyUtil.classListVo(roles, RoleVo.class);
        return RestResponse.success(roleVos);
    }
}

